package zhcms.framework.dao;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import zhcms.framework.GyReplace;
import zhcms.framework.GySplit;

public class GyGetList {
	private String sContent;
	private String currnS;
	
	public GyGetList()
	{
		sContent="";
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void ParseList(String gytFrontSeparator,String gytBackSeparator,HashMap<String, ArrayList<HashMap<String, String>>> gytInList,String ListKeyWord){
		//System.out.println("处理前中的内容:[[[[[[["+currnS);
		//System.out.println("处理中forKeyWord的内容:[[[[[[["+gytFrontSeparator+ forKeyWord + ".");
		
		Iterator<Entry<String, ArrayList<HashMap<String, String>>>> iSer = gytInList.entrySet().iterator();
		while (iSer.hasNext()) {
			Map.Entry entry = (Map.Entry) iSer.next();
			
			
			if (ListKeyWord.equals(entry.getKey().toString())) {
				ArrayList<HashMap<String, String>> gytempA = (ArrayList<HashMap<String, String>>) entry.getValue();
				// 得到块中一共有多少个变量
				GySplit e = new GySplit();
				e.tool(this.currnS, gytFrontSeparator+ ListKeyWord + ".");
				String[] itemp_array = e.Show();
				e = null;
				
				//System.out.println("得到块中一共有多少个变量["+ itemp_array.length + "]");
				
				String[] gytiParameterArray;
				gytiParameterArray = new String[itemp_array.length - 1];
				
				if (itemp_array.length > 0) {

					// 得到标签
					for (int i = 1; i < itemp_array.length; i++) {
						GySplit n = new GySplit();
						n.tool(itemp_array[i], gytBackSeparator);
						String[] temp_end_array = n.Show();
						n = null;
						// String[]
						// temp_end_array=tempContent[i].split(this.gytBackSeparator);
						gytiParameterArray[i - 1] = temp_end_array[0];

					}
				}
				
				String tempSS = "";
				// 循环块的次数
				for (int j = 0; j < gytempA.size(); j++) {
					HashMap<String, String> map = (HashMap<String, String>) gytempA
							.get(j);
					String tempLSS = "";
					String tempLSA = this.currnS;
					for (int m = 0; m < gytiParameterArray.length; m++) {
						GyReplace r = new GyReplace();
						r.replaceAllNew(tempLSA, gytFrontSeparator+ ListKeyWord + "."+ gytiParameterArray[m]+ gytBackSeparator,map.get(gytiParameterArray[m]));
						tempLSS = r.Show();
						tempLSA = r.Show();
						r = null;
					}
					tempSS = tempSS + tempLSS;
				}
				this.sContent =  tempSS ;
				//this.setsContent(tempSS);
				//System.out.println("处理后中的内容:[[[[[[["+tempSS);
			}
			
		}

	}

	public String getsContent() {
		return this.sContent;
	}

	public void setcurrnS(String currnS) {
		//System.out.println("[["+ currnS + "]");
		this.currnS = currnS;
	}
}
